import { request } from '../request';

/**
 * 获取用户信息
 *
 * @param userId 用户ID
 */
export function fetchUserInfo(userId: string) {
  return request<Api.User.UserInfo>({
    url: '/api/user/info.do',
    method: 'get',
    params: { userId }
  });
}

/**
 * 更新用户信息
 *
 * @param userInfo 用户信息
 */
export function fetchUpdateUserInfo(userInfo: Api.User.UpdateUserInfo) {
  return request<null>({
    url: '/api/user/updateInfo.do',
    method: 'post',
    data: userInfo
  });
}

/**
 * 上传头像
 *
 * @param userId 用户ID
 * @param avatarUrl 头像URL
 */
export function fetchUploadAvatar(userId: string, avatarUrl: string) {
  return request<null>({
    url: '/api/user/uploadAvatar.do',
    method: 'post',
    data: {
      userId,
      avatarUrl
    }
  });
}

/**
 * 充值余额
 *
 * @param userId 用户ID
 * @param amount 充值金额
 */
export function fetchRecharge(userId: string, amount: number) {
  return request<null>({
    url: '/api/user/recharge.do',
    method: 'post',
    params: { userId, amount }
  });
}

/**
 * 搜索用户（用户名或手机号）
 *
 * @param keyword 用户名或手机号
 */
export function searchUser(keyword: string) {
  return request({
    url: '/api/user/search.do',
    method: 'get',
    params: { keyword }
  });
}

/**
 * 获取用户余额
 *
 * @param userId 用户ID
 */
export function fetchUserBalance(userId: string) {
  return request<{ balance: number }>({
    url: '/api/user/balance.do',
    method: 'get',
    params: { userId }
  });
}
